home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
413_01
/
sbf3
/
fmprog.txt
< prev
next >
Wrap
Text File
|
1992-12-01
|
22KB
|
485 lines
Hello, all. I've updated my doc file on programming the AdLib/Sound Blaster
cards, and since I'm still getting requests for the original, I decided that
it would save time to post it here. Apologies to those who aren't interested.
-------------------------------------------------------------------------------
Programming the AdLib/Sound Blaster
FM Music Chips
Version 2.0 (24 Feb 1992)
Copyright (c) 1991, 1992 by Jeffrey S. Lee
jlee@smylex.uucp
Warranty and Copyright Policy
This document is provided on an "as-is" basis, and its author makes
no warranty or representation, express or implied, with respect to
its quality performance or fitness for a particular purpose. In no
event will the author of this document be liable for direct, indirect,
special, incidental, or consequential damages arising out of the use
or inability to use the information contained within. Use of this
document is at your own risk.
This file may be used and copied freely so long as the applicable
copyright notices are retained, and no modifications are made to the
text of the document. No money shall be charged for its distribution
beyond reasonable shipping, handling and duplication costs, nor shall
proprietary changes be made to this document so that it cannot be
distributed freely. This document may not be included in published
material or commercial packages without the written consent of its
author.
Overview
Two of the most popular sound cards for the IBM-PC, the AdLib and the
Sound Blaster, suffer from a real dearth of clear documentation for
programmers. AdLib Inc. and Creative Labs, Inc. both sell developers'
kits for their sound cards, but these are expensive, and (in the case
of the Sound Blaster developers' kit) can be extremely cryptic.
This document is intended to provide programmers with a FREE source
of information about the programming of these sound cards.
The information contained in this document is a combination of
information found in the Sound Blaster Software Developer's Kit, and
that learned by painful experience. Some of the information may not
be valid for AdLib cards; if this is so, I apologize in advance.
Please note that numbers will be given in hexadecimal, unless otherwise
indicated. If a number is written out longhand (sixteen instead of 16)
it is in decimal.
| Changes from Version 1 of the file will be indicated by the use of change
| bars in the left-hand margin.
Chapter One - Sound Card I/O
The sound card is programmed by sending data to its internal registers
via its two I/O ports:
0388 (hex) - Address/Status port (R/W)
0389 (hex) - Data port (W/O)
| The Sound Blaster Pro is capable of stereo FM music, which is accessed
| in exactly the same manner. Ports 0220 and 0221 (hex) are the address/
| data ports for the left speaker, and ports 0222 and 0223 (hex) are the
| ports for the right speaker. Ports 0388 and 0389 (hex) will cause both
| speakers to output sound.
The sound card possesses an array of two hundred forty-four registers;
to write to a particular register, send the register number (01-F5) to
the address port, and the desired value to the data port.
After writing to the register port, you must wait twelve cycles before
sending the data; after writing the data, eighty-four cycles must elapse
before any other sound card operation may be performed.
| The AdLib manual gives the wait times in microseconds: three point three
| (3.3) microseconds for the address, and twenty-three (23) microseconds
| for the data.
|
| The most accurate method of producing the delay is to read the register
| port six times after writing to the register port, and read the register
| port thirty-five times after writing to the data port.
The sound card registers are write-only.
The address port also functions as a sound card status byte. To
retrieve the sound card's status, simply read port 388. The status
byte has the following structure:
7 6 5 4 3 2 1 0
+------+------+------+------+------+------+------+------+
| both | tmr | tmr | unused |
| tmrs | 1 | 2 | |
+------+------+------+------+------+------+------+------+
Bit 7 - set if either timer has expired.
6 - set if timer 1 has expired.
5 - set if timer 2 has expired.
Chapter Two - The Registers
The following table shows the function of each register in the sound
card. Registers will be explained in detail after the table. Registers
not listed are unused.
Address Function
------- ----------------------------------------------------
01 Test LSI / Enable waveform control
02 Timer 1 data
03 Timer 2 data
04 Timer control flags
08 Speech synthesis mode / Keyboard split note select
20..35 Amp Mod / Vibrato / EG type / Key Scaling / Multiple
40..55 Key scaling level / Operator output level
60..75 Attack Rate / Decay Rate
80..95 Sustain Level / Release Rate
A0..A8 Frequency (low 8 bits)
B0..B8 Key On / Octave / Frequency (high 2 bits)
BD AM depth / Vibrato depth / Rhythm control
C0..C8 Feedback strength / Connection type
E0..F5 Wave Select
The groupings of twenty-two registers (20-35, 40-55, etc.) have an odd
order due to the use of two operators for each FM voice. The following
table shows the offsets within each group of registers for each operator.
Channel 1 2 3 4 5 6 7 8 9
Operator 1 00 01 02 08 09 0A 10 11 12
Operator 2 03 04 05 0B 0C 0D 13 14 15
Thus, the addresses of the attack/decay bytes for channel 3 are 62 for
the first operator, and 65 for the second. (The address of the second
operator is always the address of the first operator plus three).
To further illustrate the relationship, the addresses needed to control
channel 5 are:
29 - Operator 1 AM/VIB/EG/KSR/Multiplier
2C - Operator 2 AM/VIB/EG/KSR/Multiplier
49 - Operator 1 KSL/Output Level
4C - Operator 2 KSL/Output Level
69 - Operator 1 Attack/Decay
6C - Operator 2 Attack/Decay
89 - Operator 1 Sustain/Release
8C - Operator 2 Sustain/Release
A4 - Frequency (low 8 bits)
B4 - Key On/Octave/Frequency (high 2 bits)
C4 - Feedback/Connection Type
E9 - Operator 1 Waveform
EC - Operator 2 Waveform
Explanations of Registers
Byte 01 - This byte is normally used to test the LSI device. All bits
should normally be zero. Bit 5, if enabled, allows the FM
chips to control the waveform of each operator.
7 6 5 4 3 2 1 0
+-----+-----+-----+-----+-----+-----+-----+-----+
| unused | WS | unused |
+-----+-----+-----+-----+-----+-----+-----+-----+
Byte 02 - Timer 1 Data. If Timer 1 is enabled, the value in this
register will be incremented until it overflows. Upon
overflow, the sound card will signal a TIMER interrupt
(INT 08) and set bits 7 and 6 in its status byte. The
value for this timer is incremented every eighty (80)
microseconds.
Byte 03 - Timer 2 Data. If Timer 2 is enabled, the value in this